package com.lihao.demo1;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;

import com.lihao.demo1.databinding.ActivityConfirmOrderBinding;
import com.lihao.demo1.utils.BaseCompat;
import com.lihao.demo1.utils.MyNumberButton;

public class ConfirmOrderActivity extends AppCompatActivity {

    private ActivityConfirmOrderBinding binding;
    private BaseCompat baseCompat;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_confirm_order);
        initView();
        initListener();

    }
    private void initListener() {
        binding.ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        binding.llAddress.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                baseCompat.startActivityForResult(AddressInfoActivity.class,110);
            }
        });
        binding.numberButton.setNumberChangeListener(new MyNumberButton.OnNumberListener() {
            @Override
            public void onClick(CharSequence s, int start, int before, int count) {
                Toast.makeText(ConfirmOrderActivity.this, "当前库存:" + s, Toast.LENGTH_SHORT).show();
            }
        });

    }

    private void initView() {
        baseCompat=new BaseCompat(this);
        binding.numberButton.setCurrentNumber(1);

    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 110 ) {//只有操作完成才可以下一个
            String address = data.getStringExtra("address");
           binding.tvAddress.setText(address);
        }

    }

}
